package cn.wolfcode.rbac.util;

import cn.wolfcode.rbac.domain.Employee;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpSession;
import java.util.List;

public abstract class UserContext {
    public static final String EMP_IN_SESSION="EMP_IN_SESSION";

    public static final String EXPRESSION_IN_SESSION="EXPRESSION_IN_SESSION";

    public static void setCurrentUser(Employee emp){

        getSession().setAttribute("EMP_IN_SESSION",emp);
    }
    public static Employee getCurrentUser(){

        return (Employee)getSession().getAttribute("EMP_IN_SESSION");
    }
    public  static HttpSession getSession(){
        ServletRequestAttributes attrs = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        return attrs.getRequest().getSession();
    }
    //将权限保存在Session中

    public static void setExpression(List<String> permissions){
        getSession().setAttribute("EXPRESSION_IN_SESSION",permissions);
    }
    public static List<String> getExpression(){
        return (List)getSession().getAttribute("EXPRESSION_IN_SESSION");
    }
    public static String getExpressionInSession() {
        return EXPRESSION_IN_SESSION;
    }
}
